home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / drivers / mscdex / inst_cd / icsample / drvproc.c next >
Encoding:
C/C++ Source or Header  |  1992-11-11  |  11.4 KB  |  365 lines

  1. /****************************************************************************
  2.  *
  3.  *   drvproc.c
  4.  *
  5.  *   Copyright (c) 1991-1992 Microsoft Corporation.  All Rights Reserved.
  6.  *
  7.  *    You have a royalty-free right to use, modify, reproduce and 
  8.  *    distribute the Sample Files (and/or any modified version) in 
  9.  *    any way you find useful, provided that you agree that 
  10.  *    Microsoft has no warranty obligations or liability for any 
  11.  *    Sample Application Files.
  12.  *
  13.  ***************************************************************************/
  14.  
  15. #include <windows.h>
  16. #include <mmsystem.h>
  17. #include <compddk.h>
  18. #include "icsample.h"
  19.  
  20. HMODULE ghModule;
  21.  
  22. //
  23. //  we use this driverID to determine when we where opened as a video
  24. //  device or from the control panel, etc....
  25. //
  26. #define BOGUS_DRIVER_ID     1
  27.  
  28. LRESULT CALLBACK DriverProcVideo(DWORD dwDriverID, HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2);
  29.  
  30. //
  31. //  if you want to have multiple compressors in a single module add them
  32. //  to this list, for example you can have a video capture module and a
  33. //  video codec in the same module.
  34. //
  35. DRIVERPROC  DriverProcs[] = {
  36.     DriverProcVideo,  // proc for Video data
  37.  
  38.     // add other procedures here...
  39.  
  40.     NULL              // FENCE: must be last
  41. };
  42.  
  43. /***************************************************************************
  44.  ***************************************************************************/
  45.  
  46. LRESULT CALLBACK _loadds DriverProc(DWORD dwDriverID, HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2)
  47. {
  48.     INSTINFO *pi;
  49.     int        i;
  50.     LRESULT dw;
  51.  
  52.     if ( (dwDriverID == BOGUS_DRIVER_ID) || (dwDriverID == 0))
  53.         pi = NULL;
  54.     else
  55.         pi = (INSTINFO *)(UINT)dwDriverID;
  56.     
  57.     switch (uiMessage)
  58.     {
  59.         case DRV_LOAD:
  60.             DPF("DRV_LOAD");
  61.  
  62.             /*
  63.                Sent to the driver when it is loaded. Always the first
  64.                message received by a driver.
  65.  
  66.                dwDriverID is 0L. 
  67.                lParam1 is 0L.
  68.                lParam2 is 0L.
  69.                 
  70.                Return 0L to fail the load.
  71.  
  72.             */
  73.  
  74.             // put global initialization here...
  75.  
  76.         // Pass to all driver procs
  77.             for(i=0; DriverProcs[i]; i++)
  78.             {
  79.                 if (DriverProcs[i](dwDriverID, hDriver, uiMessage, lParam1, lParam2) == 0)
  80.                     return 0L;
  81.             }
  82.         
  83.             return (LRESULT)1L;
  84.  
  85.         case DRV_FREE:
  86.             DPF("DRV_FREE");
  87.  
  88.             /*
  89.                Sent to the driver when it is about to be discarded. This
  90.                will always be the last message received by a driver before
  91.                it is freed. 
  92.  
  93.                dwDriverID is 0L. 
  94.                lParam1 is 0L.
  95.                lParam2 is 0L.
  96.                 
  97.                Return value is ignored.
  98.             */
  99.  
  100.             // put global de-initialization here...
  101.  
  102.         // Pass to all driver procs
  103.             for(i=0; DriverProcs[i]; i++)
  104.                 DriverProcs[i](dwDriverID, hDriver, uiMessage, lParam1, lParam2);
  105.         
  106.             return (LRESULT)1L;
  107.  
  108.         case DRV_OPEN:
  109.             DPF("DRV_OPEN");
  110.              
  111.             /*
  112.                Sent to the driver when it is opened. 
  113.  
  114.                dwDriverID is 0L.
  115.                
  116.                lParam1 is a far pointer to a zero-terminated string
  117.                containing the name used to open the driver.
  118.                
  119.                lParam2 is passed through from the drvOpen call. It is
  120.                NULL if this open is from the Drivers Applet in control.exe
  121.                It is LPVIDEO_OPEN_PARMS otherwise.
  122.                 
  123.                Return 0L to fail the open.
  124.              */
  125.  
  126.             //
  127.             //  if we were opened without an open structure then just
  128.             //  return a phony (non zero) id so the OpenDriver() will
  129.             //  work.
  130.             //
  131.             if (lParam2 == NULL)
  132.                 return BOGUS_DRIVER_ID;
  133.  
  134.             // else, ask all procs if they like input type
  135.  
  136.             for (i=0; DriverProcs[i]; i++)
  137.         {
  138.                 if (dw = DriverProcs[i](dwDriverID, hDriver, uiMessage, lParam1, lParam2))
  139.                 {
  140.                     pi = (INSTINFO *)(UINT)dw;
  141.  
  142.                     pi->DriverProc = DriverProcs[i];
  143.                     pi->fccType = ((ICOPEN FAR *) lParam2)->fccType;
  144.  
  145.             return dw;    // they did, return
  146.         }
  147.         }
  148.         // nobody liked it,  just return zero
  149.         
  150.         return 0L;
  151.  
  152.         case DRV_QUERYCONFIGURE:
  153.         // this is a GLOBAL query configure
  154.             return (LRESULT)0L;
  155.  
  156.         case DRV_CONFIGURE:
  157.         // this is a GLOBAL configure ('cause we don't get a configure
  158.         // for each of our procs, we must have just one configure)
  159.         
  160.             return DRV_OK;
  161.  
  162.         /*********************************************************************
  163.  
  164.             standard driver messages
  165.  
  166.         *********************************************************************/
  167.  
  168.         case DRV_DISABLE:
  169.         case DRV_ENABLE:
  170.         // Pass to all driver procs
  171.             for(i=0; DriverProcs[i]; i++)
  172.                 DriverProcs[i](dwDriverID, hDriver, uiMessage, lParam1, lParam2);
  173.  
  174.             return (LRESULT)1L;
  175.  
  176.         case DRV_INSTALL:
  177.         case DRV_REMOVE:
  178.             return (LRESULT)DRV_OK;
  179.  
  180.         default:
  181.             if (pi && pi->DriverProc)
  182.                 return pi->DriverProc(dwDriverID, hDriver, uiMessage, lParam1, lParam2);
  183.             else
  184.                 return DefDriverProc(dwDriverID, hDriver, uiMessage, lParam1, lParam2);
  185.     }
  186. }
  187.  
  188.  
  189. /***************************************************************************
  190.  ***************************************************************************/
  191.  
  192. LRESULT CALLBACK DriverProcVideo(DWORD dwDriverID, HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2)
  193. {
  194.     INSTINFO *pi = (INSTINFO *)(WORD)dwDriverID;
  195.  
  196.     switch (uiMessage)
  197.     {
  198.         case DRV_LOAD:
  199.             return (LRESULT)Load();
  200.  
  201.         case DRV_FREE:
  202.             Free();
  203.             return (LRESULT)1L;
  204.  
  205.         case DRV_OPEN:
  206.         // we know we have an open struct 'cause it is checked
  207.         // in the driverproc()
  208.  
  209.             return (LRESULT)(DWORD)(WORD)Open((ICOPEN FAR *) lParam2);
  210.  
  211.         case DRV_CLOSE:
  212.             if (pi)
  213.                 Close(pi);
  214.  
  215.             return (LRESULT)1L;
  216.  
  217.         /*********************************************************************
  218.  
  219.             ICM state messages
  220.  
  221.         *********************************************************************/
  222.  
  223.         case ICM_CONFIGURE:
  224.             //
  225.             //  return ICERR_OK if you will do a configure box, error otherwise
  226.             //
  227.             if (lParam1 == -1)
  228.                 return QueryConfigure(pi) ? ICERR_OK : ICERR_UNSUPPORTED;
  229.             else
  230.                 return Configure(pi, (HWND)lParam1);
  231.  
  232.         case ICM_ABOUT:
  233.             //
  234.             //  return ICERR_OK if you will do a about box, error otherwise
  235.             //
  236.             if (lParam1 == -1)
  237.                 return QueryAbout(pi) ? ICERR_OK : ICERR_UNSUPPORTED;
  238.             else
  239.                 return About(pi, (HWND)lParam1);
  240.  
  241.         case ICM_GETSTATE:
  242.             return GetState(pi, (LPVOID)lParam1, (DWORD)lParam2);
  243.  
  244.         case ICM_SETSTATE:
  245.             return SetState(pi, (LPVOID)lParam1, (DWORD)lParam2);
  246.  
  247.         case ICM_GETINFO:
  248.             return GetInfo(pi, (ICINFO FAR *)lParam1, (DWORD)lParam2);
  249.  
  250.         /*********************************************************************
  251.         *********************************************************************/
  252.  
  253.         case ICM_GETQUALITY:
  254.         case ICM_SETQUALITY:
  255.         case ICM_GETDEFAULTQUALITY:
  256.             return ICERR_UNSUPPORTED;
  257.  
  258.         /*********************************************************************
  259.         *********************************************************************/
  260.  
  261.         case ICM_GETDEFAULTKEYFRAMERATE:
  262.             return ICERR_UNSUPPORTED;
  263.             
  264.         /*********************************************************************
  265.  
  266.             compression messages
  267.  
  268.         *********************************************************************/
  269.  
  270.         case ICM_COMPRESS_QUERY:
  271.             return CompressQuery(pi,
  272.                          (LPBITMAPINFOHEADER)lParam1,
  273.                          (LPBITMAPINFOHEADER)lParam2);
  274.  
  275.         case ICM_COMPRESS_BEGIN:
  276.             return CompressBegin(pi,
  277.                          (LPBITMAPINFOHEADER)lParam1,
  278.                          (LPBITMAPINFOHEADER)lParam2);
  279.  
  280.         case ICM_COMPRESS_GET_FORMAT:
  281.             return CompressGetFormat(pi,
  282.                          (LPBITMAPINFOHEADER)lParam1,
  283.                          (LPBITMAPINFOHEADER)lParam2);
  284.  
  285.         case ICM_COMPRESS_GET_SIZE:
  286.             return CompressGetSize(pi,
  287.                          (LPBITMAPINFOHEADER)lParam1,
  288.                          (LPBITMAPINFOHEADER)lParam2);
  289.             
  290.         case ICM_COMPRESS:
  291.             return Compress(pi,
  292.                             (ICCOMPRESS FAR *)lParam1, (DWORD)lParam2);
  293.  
  294.         case ICM_COMPRESS_END:
  295.             return CompressEnd(pi);
  296.             
  297.         /*********************************************************************
  298.  
  299.             decompress messages
  300.  
  301.         *********************************************************************/
  302.  
  303.         case ICM_DECOMPRESS_QUERY:
  304.             return DecompressQuery(pi,
  305.                          (LPBITMAPINFOHEADER)lParam1,
  306.                          (LPBITMAPINFOHEADER)lParam2);
  307.  
  308.         case ICM_DECOMPRESS_BEGIN:
  309.             return DecompressBegin(pi,
  310.                          (LPBITMAPINFOHEADER)lParam1,
  311.                          (LPBITMAPINFOHEADER)lParam2);
  312.  
  313.         case ICM_DECOMPRESS_GET_FORMAT:
  314.             return DecompressGetFormat(pi,
  315.                          (LPBITMAPINFOHEADER)lParam1,
  316.                          (LPBITMAPINFOHEADER)lParam2);
  317.  
  318.         case ICM_DECOMPRESS_GET_PALETTE:
  319.             return DecompressGetPalette(pi,
  320.                          (LPBITMAPINFOHEADER)lParam1,
  321.                          (LPBITMAPINFOHEADER)lParam2);
  322.  
  323.         case ICM_DECOMPRESS:
  324.             return Decompress(pi,
  325.                          (ICDECOMPRESS FAR *)lParam1, (DWORD)lParam2);
  326.  
  327.         case ICM_DECOMPRESS_END:
  328.             return DecompressEnd(pi);
  329.  
  330.         /*********************************************************************
  331.  
  332.             draw messages
  333.  
  334.         *********************************************************************/
  335.  
  336.         case ICM_DRAW_QUERY:
  337.             return DrawQuery(pi,(LPBITMAPINFOHEADER)lParam1)
  338.                 ? ICERR_OK : ICERR_UNSUPPORTED;
  339.  
  340.         case ICM_DRAW_BEGIN:
  341.             return DrawBegin(pi,(ICDRAWBEGIN FAR *)lParam1, (DWORD)lParam2);
  342.  
  343.         case ICM_DRAW:
  344.             return Draw(pi,(ICDRAW FAR *)lParam1, (DWORD)lParam2);
  345.  
  346.         case ICM_DRAW_END:
  347.             return DrawEnd(pi);
  348.             
  349.     }
  350.  
  351.     if (uiMessage < DRV_USER)
  352.         return DefDriverProc(dwDriverID, hDriver, uiMessage, lParam1, lParam2);
  353.     else
  354.         return ICERR_UNSUPPORTED;
  355. }
  356.  
  357. /****************************************************************************
  358.  ***************************************************************************/
  359. int NEAR PASCAL LibMain(HMODULE hModule, WORD wHeapSize, LPSTR lpCmdLine)
  360. {
  361.     ghModule = hModule;
  362.  
  363.     return 1;
  364. }
  365.